< previous page page_502 next page >

Page 502
The Bezier3d class stores and displays Bezier surfaces. This class holds the control point data in an array of the Point3D data type. Variables MaxU and MaxV hold the maximum values for u and v needed to draw the surface. The class provides a SetControlPoint method to initialize the control point coordinates.
After the control points are initialized, the InitializeGrid subroutine creates points on the surface and stores them in Polyline3d objects. To manipulate the data, the Bezier3dclass passes subroutine calls to these objects. For example, to apply a transformation matrix to the surface, the object calls the Apply method for each of its Polyline3d objects.
InitializeGrid calls the SurfaceValue subroutine to calculate the coordinates of points on the surface. Subroutine SurfaceValue uses the Bezier surface equations to calculate the X, Y, and Z coordinates of a point with particular u and v parameter values. The most interesting parts of the Bezier3d object are shown in the following code. You can see the rest of the code in the module Bezier.cls on the CD-ROM.
e10a6a0a59f035e870d90cca05b85fce.gif
Private MaxU As Integer     ' Dimensions of control grid.
Private MaxV As Integer
Private Points() As Point3D ' Control points.

' Holds polylines containing the refined
' grid to display the surface.
Private Polylines As Collection

' u and v increment parameters.
Private GapU As Single
Private GapV As Single
Private Du As Single
Private Dv As Single

' Set MaxU and MaxV and allocate room for the
' control points.
Public Sub SetBounds(_
    ByVal NumX As Integer, ByVal NumZ As Integer)

    MaxU = NumX - 1
    MaxV = NumZ - 1
    ReDim Points(O To NumX, 0 To NumZ)
End Sub

' Set the value for a control point.
Public Sub SetControlPoint( _
    ByVal i As Integer, ByVal j As Integer, _
    ByVal X As Single, ByVal Y As Single, ByVal Z As Single)

    Points(i - 1, j - 1).coord(1) = X
    Points(i - 1, j - 1).coord(2) = Y
    Points(i - 1, j - 1).coord(3) = Z
    Points(i - 1, j - 1).coord(4) = 1
End Sub

 
< previous page page_502 next page >